USE NutritionTracker
GO
IF EXISTS (SELECT 1 FROM sysobjects WHERE ID = object_id(N'AppUser_AppRole_Read_List') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
	DROP PROCEDURE AppUser_AppRole_Read_List
GO
CREATE PROC AppUser_AppRole_Read_List
(
@AppUserID	INT,
@AppRoleID	TINYINT = NULL
)
AS
BEGIN
	SET NOCOUNT ON

	SELECT		AppRole.AppRoleID,
			AppRoleName		
	FROM		AppRole
	INNER JOIN	AppUser_AppRole
		ON		AppRole.AppRoleID = AppUser_AppRole.AppRoleID
	WHERE		AppUser_AppRole.AppUserID = @AppUserID
	AND		AppUser_AppRole.AppRoleID = ISNULL(@AppRoleID,AppUser_AppRole.AppRoleID)
	ORDER BY		AppRoleName

	SET NOCOUNT OFF
END
GO
GRANT EXECUTE ON AppUser_AppRole_Read_List TO NUTRKR_WEB
GO